package com.opensource.baodaoimpl.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.opensource.common.contant.SystemConstants;
import com.opensource.datamodel.dto.IndexProductListDto;
import com.opensource.datamodel.entity.ProductInfoEntity;
import com.opensource.datamodel.service.ProductInfoService;
import com.opensource.baodaoimpl.mapper.ProductInfoMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* @author 25133
* @description 针对表【b_product_info(理财产品信息表)】的数据库操作Service实现
* @createDate 2024-05-07 19:42:52
*/
@DubboService(interfaceClass = ProductInfoService.class,version = "1.0")
public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, ProductInfoEntity>
    implements ProductInfoService {

    @Autowired
    private ProductInfoMapper productInfoMapper;

    @Override
    public List<ProductInfoEntity> queryByTypeLimit(Integer pType, Integer curPage, Integer pageSize) {
            return productInfoMapper.selectByTypeLimit(pType,curPage,pageSize);
    }

    @Override
    public Integer queryToTalByType(Integer pType) {

        LambdaQueryWrapper<ProductInfoEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductInfoEntity::getProductType,pType);
       return Math.toIntExact(productInfoMapper.selectCount(wrapper));

    }

    @Override
    public IndexProductListDto queryIndexPageProducts() {
    //    新手宝 1个
        List<ProductInfoEntity> xinShouList = queryByTypeLimit(SystemConstants.PRODUCT_TYPE_XINSHOUBAO, 1, 1);
        //    优选  4个
        List<ProductInfoEntity> youXuanList = queryByTypeLimit(SystemConstants.PRODUCT_TYPE_YOUXUAN, 1, 3);
        //    散标 8个
        List<ProductInfoEntity> sanBiaoList = queryByTypeLimit(SystemConstants.PRODUCT_TYPE_SANBIAO, 1, 3);
        return new IndexProductListDto(xinShouList,youXuanList,sanBiaoList);
    }

    @Override
    public Integer queryRecordNumsByType(Integer productType) {
        LambdaQueryWrapper<ProductInfoEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductInfoEntity::getProductType,productType);
        Long count = productInfoMapper.selectCount(wrapper);
        return Math.toIntExact(count);
    }

    @Override
    public ProductInfoEntity queryById(Integer productId) {
       return productInfoMapper.selectById(productId);
    }


}




